using System;
using System.Drawing;
using System.Windows.Forms;
using System.Reflection;
using System.IO;
using System.Runtime.InteropServices;

namespace ImageRecognition2.Forms
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FormScreenshot : Form
    {
        protected Image m_ImageScreenshot = null;

        /// <summary>
        /// Initializes a new instance of the <see cref="ScreenshotForm"/> class.
        /// </summary>F
        public FormScreenshot()
        {
            InitializeComponent();

            InitializeListBox();

            chkbTimer.CheckedChanged += delegate(object sender, EventArgs e)
            {
                numericUpDown1.Enabled = chkbTimer.Checked;
            };

            listBox1.DoubleClick += delegate(object sender, EventArgs e)
            {
                this.tbWindowName.Text = listBox1.SelectedItem.ToString();
            };
        }

        /// <summary>
        /// Gets the screenshot.
        /// </summary>
        /// <value>The screenshot.</value>
        public Image Screenshot
        {
            get { return m_ImageScreenshot; }
        }

        /// <summary>
        /// Initializes the list box.
        /// </summary>
        private void InitializeListBox()
        {
            string[] aWindow = Win32Helpers.GetDesktopWindowsCaptions();
            foreach (string sWindow in aWindow)
            {
                if (!string.IsNullOrEmpty(sWindow)&& sWindow != "Default IME")
                {
                    this.listBox1.Items.Add(sWindow);
                }
            }
        }

        /// <summary>
        /// Handles the Click event of the TakeScreenshot control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void TakeScreenshot_Click(object sender, EventArgs e)
        {
            m_ImageScreenshot = ImageTools.TakeScreenshot(tbWindowName.Text, chkbCompleteDesktop.Checked);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}